package leetcode;

import java.util.Arrays;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0242.java
 * @Author : WangRuoyu
 * @Date 2023/11/8 10:58
 */


public class Q0242 {
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        int[] cnts = new int[26];
        int[] cntt = new int[26];
        for (int i = 0; i < s.length(); i++) {
            cnts[s.charAt(i) - 'a']++;
            cntt[t.charAt(i) - 'a']++;
        }
        return Arrays.equals(cnts, cntt);
    }

    public static void main(String[] args) {
        Q0242 sl = new Q0242();
        String s = "anagram";
        String t = "nagaram";
        System.out.println(sl.isAnagram(s, t));
    }
}